/*
 * File:   924.cpp
 * Author: xerxes
 *
 * Created on September 16, 2011, 2:24 PM
 *
 * I have not failed, I have just found 10000 ways that won't work.
 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

inline void wait(double seconds) {
    double endtime = clock()+(seconds * CLOCKS_PER_SEC);
    while (clock() < endtime) {
        ;
    }
}

int ne; //number of employee
vector< VI > p; //path
int boom[2505];
int hash[2505];
inline void Read() {
    p.assign(ne + 5, VI());

    fo(i, 0, ne) {
        int n;
        CI(n);

        fo(j, 0, n) {
            int x;
            CI(x);
            p[i].pb(x);
        }
    }
}

inline void bfs(int e) {

    queue< int > q;
    SET(boom, -1);
    SET(hash, 0 );

    q.push(e);
    boom[e] = 0;
    hash[0] = 0;
    while (q.empty()==false) {
        int father = q.front();
        q.pop();

        for (int i = 0, j = SZ(p[father]); i < j; ++i) {
            int child = p[father][i];
            if (boom[child] == -1){
                boom[ child ] = boom[father] + 1;
                hash[ boom[child] ]++;
                q.push(child);
            }
        }
    }
    
    if( count(boom,boom+ne,-1)== (ne-1) ){
        cout<<0<<"\n";
        return ;
    }
    int a=-1;
    int b=0;
    fo(i,0,ne+5){
        if( hash[i] > a ){
            a = hash[i];
            b = i;
        }
    }
    cout<<a<<" "<<b<<"\n";
    
}

inline void Proc() {
    int t;
    CI(t);
    while (t--) {
        int x;
        CI(x);
        bfs(x);
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "rt", stdin);
#endif

    while (scanf("%d", &ne) == 1) {
        Read();
        Proc();
    }

    return 0;
}


